package com.learn.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 *
 *
 * @author: hbliy
 * @date: 2025/11/5 09:09
 */
@RestController
@RequestMapping("/config")
public class ConfigController {

    private final Environment environment;

    // 要获取的配置项列表（与你提供的配置对应）
    private static final List<String> CONFIG_KEYS = Arrays.asList(
            "server.error.include-binding-errors",
            "server.error.include-message",
            "server.error.include-stacktrace",
            "server.servlet.jsp.init-parameters.development",
            "server.servlet.session.persistent",
            "spring.docker.compose.readiness.wait",
            "spring.freemarker.cache",
            "spring.graphql.graphiql.enabled",
            "spring.groovy.template.cache",
            "spring.h2.console.enabled",
            "spring.mustache.servlet.cache",
            "spring.mvc.log-resolved-exception",
            "spring.reactor.netty.shutdown-quiet-period",
            "spring.template.provider.cache",
            "spring.thymeleaf.cache",
            "spring.web.resources.cache.period",
            "spring.web.resources.chain.cache"
    );


    public ConfigController(Environment environment) {
        this.environment = environment;
    }


    @GetMapping("/print")
    public String println() {
        System.out.println("===== 配置值输出 =====");
        for (String key : CONFIG_KEYS) {
            String value = environment.getProperty(key);
            System.out.printf("%s = %s%n", key, value);
        }
        System.out.println("======================");
        return "ConfigController.println 22222";
    }

//
//    @Value("${server.error.include-binding-errors}")
//    private String includeBindingErrors;
//    @Value("${server.error.include-message}")
//    private String includeMessage;
//    @Value("${server.error.include-stacktrace}")
//    private String includeStacktrace;
//    @Value("${server.servlet.jsp.init-parameters.development}")
//    private String initParametersDevelopment;
//    @Value("${server.servlet.session.persistent}")
//    private String sessionPersistent;
//    @Value("${spring.docker.compose.readiness.wait}")
//    private String dockerComposeReadinessWait;
//    @Value("${spring.freemarker.cache}")
//    private String freemarkerCache;
//    @Value("${spring.graphql.graphiql.enabled}")
//    private String graphiqlEnabled;
//    @Value("${spring.groovy.template.cache}")
//    private String groovyTemplateCache;
//    @Value("${spring.h2.console.enabled}")
//    private String h2ConsoleEnabled;
//    @Value("${spring.mustache.servlet.cache}")
//    private String mustacheServletCache;
//    @Value("${spring.mvc.log-resolved-exception}")
//    private String mvcLogResolvedException;
//    @Value("${spring.reactor.netty.shutdown-quiet-period}")
//    private String reactorNettyShutdownQuietPeriod;
//    @Value("${spring.template.provider.cache}")
//    private String templateProviderCache;
//    @Value("${spring.thymeleaf.cache}")
//    private String thymeleafCache;
    @Value("${spring.web.resources.cache.period:0}")
    private String webResourcesCachePeriod;
    @Value("${spring.web.resources.chain.cache:false}")
    private String webResourcesChainCache;

    @GetMapping("/print2")
    public String print2() {

//        System.out.println("includeBindingErrors:" + includeBindingErrors);
//        System.out.println("includeMessage:" + includeMessage);
//        System.out.println("includeStacktrace:" + includeStacktrace);
//        System.out.println("initParametersDevelopment:" + initParametersDevelopment);
//        System.out.println("sessionPersistent:" + sessionPersistent);
//        System.out.println("dockerComposeReadinessWait:" + dockerComposeReadinessWait);
//        System.out.println("freemarkerCache:" + freemarkerCache);
//        System.out.println("graphiqlEnabled:" + graphiqlEnabled);
//        System.out.println("groovyTemplateCache:" + groovyTemplateCache);
//        System.out.println("h2ConsoleEnabled:" + h2ConsoleEnabled);
//        System.out.println("mustacheServletCache:" + mustacheServletCache);
//        System.out.println("mvcLogResolvedException:" + mvcLogResolvedException);
//        System.out.println("reactorNettyShutdownQuietPeriod:" + reactorNettyShutdownQuietPeriod);
//        System.out.println("templateProviderCache:" + templateProviderCache);
//        System.out.println("thymeleafCache:" + thymeleafCache);
        System.out.println("webResourcesCachePeriod:" + webResourcesCachePeriod);
        System.out.println("webResourcesChainCache:" + webResourcesChainCache);

        return "ConfigController.println";
    }

    @Value("${location:'unknow'}")
    private String location;

    @GetMapping("/value")
    public String config() {
        return location;
    }
}
